//
//  PSNodeTests.m
//  PrefCore
//
//  Created by Sergey on 5/12/14.
//  Copyright (c) 2014 Play-on-smart. All rights reserved.
//

#import <XCTest/XCTest.h>
#import "PSNode.h"
#import "PSMove.h"

@interface PSNodeTests : XCTestCase

@end

@implementation PSNodeTests

- (void)testCreateRoot {
    PSTreeLevel *lvl = [[PSTreeLevel alloc] initWithRound:123];
    PSNode *node = [PSNode nodeWithLevel:lvl starter:0 hand0:1 hand1:2 hand2:4];
    XCTAssertNotNil(node);
}

- (void)testCreateChild {
    PSTreeLevel *lvl = [[PSTreeLevel alloc] initWithRound:123];
    PSNode *root = [PSNode nodeWithLevel:lvl starter:0 hand0:1 hand1:2 hand2:4];
    PSHandHash hands[3] = {};
    PSNode *child = [PSNode
        nodeWithLevel:lvl
               parent:root
                hands:hands
               player:0
               winner:1
                card0:[PSCard cardWithIndex:1]
                card1:[PSCard cardWithIndex:2]
                card2:[PSCard cardWithIndex:3]
    ];
    XCTAssertNotNil(child);
}

-(void)testSet {
    XCTAssertNotNil([PSNode set]);
}

-(void)testDestroy {
    PSTreeLevel *lvl = [[PSTreeLevel alloc] initWithRound:123];
    PSNode *node = [PSNode nodeWithLevel:lvl starter:0 hand0:1 hand1:2 hand2:4];
    XCTAssertNotNil(node);
    [node.children addLast:
        [PSMove moveWithCard0:[PSCard cardWithIndex:1]
                        card1:[PSCard cardWithIndex:2]
                        card2:[PSCard cardWithIndex:3]
                      andNode:node]
    ];
    [[PSNode set] put:node];
    [lvl clearExcept:nil];
}

-(void)testDescription {
    PSTreeLevel *lvl = [[PSTreeLevel alloc] initWithRound:123];
    PSNode *node = [PSNode nodeWithLevel:lvl starter:0 hand0:1 hand1:2 hand2:4];
    XCTAssertEqualObjects(@"pa: 0 sc: --- w: 0 st: 0 ch: 0 h0: ♥: 7 h1: ♥: 8 h2: ♥: 9", [node description]);
}

@end
